package com.imooc.security.config;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author : cjf
 * @date : 2021-03-16 10:27
 **/
@RestControllerAdvice
public class ErrorHandler {

    @ExceptionHandler(Exception.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public Map<String, Object> handle(Exception ex){
        Map<String,Object> info = new HashMap<>();
        info.put("message",ex.getMessage());
        info.put("time",System.currentTimeMillis());
        return info;
    }
}
